package com.wwg.algorithm_data_structures;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * @author wuweigang
 */

@Getter
@Setter
public class Node {

    Node pre;
    Node next;
    int name;

    private void reverse() {
        Node pre = this.getPre();
        Node next = this.getNext();

        if (next != null) {
            this.setPre(next);
        }

        if (pre == null) {
            this.setNext(null);
        }

        if (next == null) {
            this.setPre(null);
        }

        if (pre != null) {
            this.setNext(pre);
            pre.reverse();
        }
    }

    public static void main(String[] args) {

        Node node1 = new Node();
        node1.setName(1);

        Node node2 = new Node();
        node2.setName(2);

        Node node3 = new Node();
        node3.setName(3);

        node1.setNext(node2);

        node2.setPre(node1);
        node2.setNext(node3);

        node3.setPre(node2);

        node3.reverse();

        System.out.println(node3);
    }

}

